using System;
using System.Collections.Generic;
using System.Text;
using Terminal.Advanced_AEUC_settings_controls.Settings_Interfaces;
using System.Windows.Forms;

namespace Terminal.Advanced_AEUC_settings_controls.Settings_AUX
{
    /// <summary>
    /// Simple class defining a relation between a message status and unique id
    /// </summary>
    public class GenMSGStatus : IAEUCSerialization
    {
        /// <summary>
        /// Unique message status
        /// </summary>
        public uint UID = 0x0000;
        /// <summary>
        /// Human friendly message status
        /// </summary>
        public string DisplayString = "MESSAGE_STATUS";
        /// <summary>
        /// Overrided ToString() method of the class
        /// </summary>
        /// <returns>String representation of the object</returns>
        public override string ToString()
        {
            return DisplayString;
        }

        #region ISerialization Members
        /// <summary>
        /// Current element serialization state version
        /// </summary>
        public int serVersion
        {
            get
            {
                return 0x000;
            }
        }
        /// <summary>
        /// Saves this objec instance to a file
        /// </summary>
        /// <param name="srWriter">Binray writer of the associated file</param>
        public void Serialize(System.IO.BinaryWriter srWriter)
        {
            srWriter.Write(serVersion);
            Serialize_v000(srWriter);
        }
        /// <summary>
        /// Loads this objects instance from a file
        /// </summary>
        /// <param name="srReader">Binray reader of the associated file</param>
        /// <returns>Boolean representing the success of the operation</returns>
        public bool Deserialize(System.IO.BinaryReader srReader)
        {
            bool desProcState;
            int serialVer = srReader.ReadInt32();

            switch (serialVer)
            {
                case 0x000:
                    desProcState = Deserialize_v000(srReader);
                    break;
                default:
                    desProcState = false;
                    break;
            }

            return desProcState;
        }

        #region Version 0x000 serialization
        /// <summary>
        /// Version 0x000 serialization
        /// </summary>
        /// <param name="srWriter">File writer</param>
        void Serialize_v000(System.IO.BinaryWriter srWriter)
        {
            srWriter.Write(UID);
            srWriter.Write(DisplayString);
        }
        /// <summary>
        /// Version 0x000 deserialization
        /// </summary>
        /// <param name="srReader">File reader</param>
        /// <returns>True if operation is succesful</returns>
        bool Deserialize_v000(System.IO.BinaryReader srReader)
        {
            bool success;
            try
            {
                UID = srReader.ReadUInt32();
                DisplayString = srReader.ReadString();
                success = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                success = false;
            }
            return success;
        }
        #endregion
        #endregion
    }
}
